package com.freak.neteasecloudmusic.modules.find.recommend.songlist.detail.comment;


import com.freak.httphelper.ApiCallback;
import com.freak.httphelper.HttpMethods;
import com.freak.httphelper.RxPresenter;
import com.freak.httphelper.SubscriberCallBack;
import com.freak.neteasecloudmusic.app.api.ApiService;
import com.freak.neteasecloudmusic.commom.constants.Constants;
import com.freak.neteasecloudmusic.modules.find.recommend.songlist.detail.comment.entity.CommentEntity;
import com.freak.neteasecloudmusic.utils.ToastUtil;

import io.reactivex.Observable;

/**
 * Created by Freak on 2020/3/7.
 */
public class CommentPresenter extends RxPresenter<CommentContract.View> implements CommentContract.Presenter {
    private ApiService mApiService = HttpMethods.getInstance().create(ApiService.class);

    @Override
    public void getCommentList(String id, String limit, String offset, String before) {
        Observable<CommentEntity> observable = mApiService.getCommentList(id, limit, offset, before);
        addSubscription(observable, new SubscriberCallBack<CommentEntity>(new ApiCallback<CommentEntity>() {
            @Override
            public void onSuccess(CommentEntity model) {
                if (model.getCode() == Constants.SUCCESS_CODE) {
                    mView.getCommentListSuccess(model);
                } else {
                    ToastUtil.shortShow("获取失败");
                }
            }

            @Override
            public void onFailure(String msg) {
                ToastUtil.shortShow(msg);
            }
        }));
    }
}
